<?php if (!$this->allow()) : ?>
	<div><?php echo $this->translator->translator('previlege_Access_deny_desc'); ?></div>
<?php else : ?>

<script type="text/javascript">
	$(function() {
		$(".row").sortable({
			connectWith: '.row'
		});
		
		$(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
			.find(".portlet-header")
				.addClass("ui-widget-header ui-corner-all")
				.prepend('<span class="ui-icon ui-icon-minusthick"></span>')
				.end()
			.find(".portlet-content");

		$(".portlet-header .ui-icon").click(function() {
			$(this).toggleClass("ui-icon-minusthick").toggleClass("ui-icon-plusthick");
			$(this).parents(".portlet:first").find(".portlet-content").toggle();
		});
		
		$("#accordion").accordion( {
			collapsible:true,
			heightStyle: "content"
		});
	});
	/*jQuery(document).ready(function(){
		$('#accordion').click(function() {
			$(this).next().toggle();
			return false;
		}).next().hide();
	});*/
$(document).ready(function() {
	$('a.tSelectAll').click(function() {
		$(this).parent().find('input[type="checkbox"]').each(function() {
			$(this).attr('checked', true);
		});
	});
	$('a.tDeselectAll').click(function() {
		$(this).parent().find('input[type="checkbox"]').each(function() {
			$(this).attr('checked', false);
		});
	});
	
	$('input.btn_1').click(function() {
		var val = '';
		var allVal = '';
		var ajax_loader = $(this).parent().find('#ajax_loader');
		var role_id = $("#role_id").val();
		$(this).parent().parent().find('input[type="checkbox"]').each(function() {			
			allVal += $(this).attr('value')+',';
		});
		$(this).parent().parent().find('input[type="checkbox"]:checked').each(function() {			
			val += $(this).attr('value')+',';
		});
		ajax_loader.html('<img src="application/modules/Administrator/layouts/scripts/images/loader/ajax_loader.gif" border="0" height="16" />');	
		$.ajax({
			  url: "<?php echo $this->url( array('module'=> 'Administrator', 'controller' => 'rule', 'action'     => 'roleupdate' ), 'adminrout',    true) ?>",
			  type: 'POST',
			  data: { privileges: val, role_id: role_id, allVal:allVal },
			  success: function(response)
			  {
			  	var json_arr = eval("("+response+")");
				var msg = json_arr.msg;
			  	ajax_loader.html('');
				$.fx.speeds._default = 1000;						
				$('#dialog_container').html(msg).dialog({
					autoOpen: true,
					modal: false,
					show: 'fade',
					hide: 'explode',
					buttons: { "Ok": function() { $(this).dialog("close"); } },
					open: function(event, ui)
						 {
							setTimeout(function() 
							{
								$('#' + event.target.id).dialog('option', 'hide', 'explode').dialog('destroy');
							}, 10000);
						  }
				});
			  }
		});		
	});
});
</script>

<div id="container" class="permission-settings">
<div class="title-container">
	<div class="role-setup"><h1><?php echo $this->translator->translator('permisson_rule_role_setting_page'); ?></h1></div> <div class="userid label"><?php echo ' ('.$this->role[0]['role_name']; ?> - <?php echo $this->role[0]['role_desc'].')'; ?></div>
</div>

<div class="content-container">
<?php if ($this->role[0]['role_lock'] == 0) : ?>
	<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('rule_role_role_desc'); ?>: <b><?php echo $this->role[0]['role_name']; ?> - <?php echo $this->role[0]['role_desc']; ?></b><br />
		<?php echo $this->translator->translator('rule_role_role_locked'); ?>
	</div>
	<?php else : ?>
    <div class="settings-area">
		<p>
			<?php echo $this->translator->translator('rule_role_role_desc'); ?><br />
			<span class="label"><?php echo $this->translator->translator('rule_role_guide'); ?><input type="hidden" name="role_id" id="role_id" value="<?php echo $this->role_id; ?>" /></span>
		</p>
        <div class="clr"></div>
		<div id="accordion">
			<?php	
				foreach ($this->modules as $module) : 				
			?>
				<h3><a href="#"><?php  echo $module;  ?></a></h3>
				<div>					
					<?php $resources = $this->ruleLoader()->getResources($module); if ($resources) : ?>
						<div class="row">
							<?php for ($i = 0; $i < count($resources); $i++) : ?>
								<div class="portlet">
									<div class="portlet-header tab_header_1">
										<?php echo $this->escape(stripslashes($resources[$i]['resource_description'])); ?>
									</div>	
									<div class="portlet-content grid_panel_text">
										<a class="tSelectAll" href="javascript: void(0)"><?php echo $this->translator->translator('rule_role_select_all'); ?></a> | <a class="tDeselectAll" href="javascript: void(0)"><?php echo $this->translator->translator('rule_role_deselect_all'); ?></a>
										<hr />
										<?php 
											$privileges = $this->ruleLoader()->getPrivilegesByRole($resources[$i], $this->role[0]['role_id']); 
											
											foreach ($privileges as $priv) :
										?>
										<input type="checkbox" name="privileges[]" value="<?php echo $priv['privilege_id']; ?>_<?php echo $resources[$i]['module_name']; ?>:<?php echo $resources[$i]['controller_name']; ?>"<?php if ($priv['allow'] == null || $priv['allow'] == 0) : ?> <?php else : ?> checked="checked"<?php endif; ?> /> <?php echo stripslashes($priv['privilege_description']); ?><br />
										<?php endforeach; ?>
                                        <hr />
										<div><?php if ($this->allow('roleupdate')) : ?><input type="button" name="save" id="save" value="<?php echo $this->translator->translator('common_save'); ?>"  class="btn_1" /><?php endif; ?>&nbsp;<span id="ajax_loader"></span></div>
									</div>									
								</div>
								<?php
									if(($i+1) % 3 == 0)
									{
										echo '</div><div class="row" >';
									}
								?>
							<?php endfor; ?>
						</div>
					<?php endif; ?>						
				</div>
			<?php 	
			endforeach; 
			?>		
		</div>
  	</div>
	<?php endif; ?>
</div>
<div id="dialog_container" title="<?php echo $this->translator->translator('common_dialog_msg',$this->translator->translator('Role List')); ?>"></div>
</div>
<?php endif; ?>